//
//  RegEncyViewController.m
//  安好
//
//  Created by 冯凯 on 14-5-23.
//  Copyright (c) 2014年 冯凯. All rights reserved.
//

#import "RegEncyViewController.h"

@interface RegEncyViewController ()

@end

@implementation RegEncyViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self makeNavBar];
    [self actionView1];
   
    [self viewWithWeb];
    
    self.view.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
}
#pragma mark - 导航条设置
-(void)makeNavBar
{
    self.navigationItem.title = @"挂号网";
    //左按钮--返回
    UIBarButtonItem *backBtnImg = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"公用_返回.png"] style:UIBarButtonItemStylePlain target:self action:@selector(backClicked)];
    [backBtnImg setTintColor:[UIColor whiteColor]];
    self.navigationItem.leftBarButtonItem = backBtnImg;
}
//返回
-(void)backClicked
{
    [self.navigationController popViewControllerAnimated:YES];
    [self hidden1];
}
- (void)actionView1
{
    self.mbPro = [[MBProgressHUD alloc]initWithView:self.view];
    [self.mbPro setLabelText:@"安好正在为你加载第三方挂号平台"];
    [self.navigationController.view.superview addSubview:self.mbPro];
}
- (void)viewWithWeb
{
    UIWebView * webView = [[UIWebView alloc]init];
    webView.frame = CGRectMake(0,0, kScreenWidth, kScreenHeight -iOS7TopMargin);
    webView.delegate = self;
    NSString * string = [NSString stringWithFormat:@"http://m.guahao.com/mobile/expert/%@",self.doctorid];
    NSURLRequest *request =[NSURLRequest requestWithURL:[NSURL URLWithString:string]];
    [self.view addSubview: webView];
    [webView loadRequest:request];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void) webViewDidStartLoad:(UIWebView *)webView
{
    [self show1];
    //创建UIActivityIndicatorView背底半透明View
    UIView *view = [[UIView alloc] init];
    
        view.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight );
        

    [view setTag:108];
    [view setBackgroundColor:[UIColor blackColor]];
    [view setAlpha:0.5];
    [self.view addSubview:view];

}

- (void) webViewDidFinishLoad:(UIWebView *)webView
{
    [self hidden1];
    UIView *view = (UIView*)[self.view viewWithTag:108];
    [view removeFromSuperview];
    
}
- (void) webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    UIView *view = (UIView*)[self.view viewWithTag:108];
    [view removeFromSuperview];
}
- (void)viewDidDisappear:(BOOL)animated
{
    UIView *view = (UIView*)[self.view viewWithTag:108];
    [view removeFromSuperview];
}
- (void)show1
{
    self.mbPro.mode = MBProgressHUDModeIndeterminate;
    [self.mbPro show:YES];
}

- (void)hidden1
{
    self.mbPro.mode = MBProgressHUDModeIndeterminate;
    [self.mbPro hide:YES];
}
@end
